package com.maxlen.member.controller.reception;

import com.maxlen.common.utils.PageUtils;
import com.maxlen.common.utils.R;
import com.maxlen.member.entity.MemberEntity;
import com.maxlen.member.entity.dto.MemberSaveDTO;
import com.maxlen.member.entity.vo.LoginVO;
import com.maxlen.member.entity.vo.UserRegisterVO;
import com.maxlen.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/member/reception")
public class ReceptionController {

    @Autowired
    private MemberService memberService;

    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginVO loginVO){
        return memberService.login(loginVO);
    }

    /**
     * gitee 登录
     * @param code
     * @return
     */
    @GetMapping("/giteeLogin")
    public R OAuthGiteeLogin(@RequestParam("code") String code){
        return memberService.OAuthGiteeLogin(code);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("member:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 会员注册
     * @param userRegisterVO
     * @return
     */
    @PostMapping("/register")
    public R register(@Validated @RequestBody UserRegisterVO userRegisterVO){
        return memberService.register(userRegisterVO);
    }

    /**
     * 发送短信验证
     * @param phone
     * @return
     */
    @GetMapping("/sms/sendCode")
    public R sendCode(@RequestParam("phone") String phone){
        return memberService.sendCode(phone);
    }

    /**
     * 判断用户名是否唯一
     * @param username
     * @return
     */
    @GetMapping("/isExistUsername")
    public R isExistUsername(@RequestParam("username") String username){
        return memberService.isExistUsername(username);
    }

    /**
     * 判断手机号是否唯一
     * @param phone
     * @return
     */
    @GetMapping("/isExistPhone")
    public R isExistPhone(@RequestParam("phone") String phone){
        return memberService.isExistPhone(phone);
    }

    /**
     * 判断邮箱是否唯一
     * @param email
     * @return
     */
    @GetMapping("/isExistEmail")
    public R isExistEmail(@RequestParam("email") String email){
        return memberService.isExistEmail(email);
    }

    /**
     * 获取用户信息
     * @param token
     * @return
     */
    @PostMapping("/getCurrentUser")
    public R getCurrentUser(@RequestBody String token) {
        return memberService.getCurrentUser(token);
    }

    /**
     * 保存用户信息
     * @param memberSaveDTO
     * @return
     */
    @PostMapping("/saveCurrentUser")
    public R saveCurrentUser(@RequestBody MemberSaveDTO memberSaveDTO) {
        return memberService.saveCurrentUser(memberSaveDTO);
    }

}
